WINS









How do I use W I N S
Below are practical examples compiled from projects for learning and reference purposes

Featured Snippets


File name: GameManager.cs Copy
27  void OnGUI() {
28   GUI.skin = layout;
29   GUI.Label (new Rect (Screen.width / 2 - 150 - 12, 20, 100, 100), "" + PlayerScore1);
30   GUI.Label (new Rect (Screen.width / 2 + 150 + 12, 20, 100, 100), "" + PlayerScore2);
31
32   if (GUI.Button (new Rect (Screen.width / 2 - 60, 35, 120, 53), "RESTART")) {
33    PlayerScore1 = 0;
34    PlayerScore2 = 0;
35    theBall.SendMessage ("RestartGame", 0.5f, SendMessageOptions.RequireReceiver);
36   }
37
38   if (PlayerScore1 == 10) {
39    GUI.Label (new Rect (Screen.width / 2 - 150, 200, 2000, 1000), "PLAYER ONE WINS");
40    theBall.SendMessage ("ResetBall", null, SendMessageOptions.RequireReceiver);
41   } else if (PlayerScore2 == 10) {
42    GUI.Label (new Rect (Screen.width / 2 - 150, 200, 2000, 1000), "PLAYER TWO WINS");
43    theBall.SendMessage ("ResetBall", null, SendMessageOptions.RequireReceiver);
44   }
45  }
File name: GameManager.cs Copy
278  public void GameOver(GCPlayer winner, GameOverType gameOverType) {
279   AddGame();
280   switch (gameOverType) {
281    case GameOverType.CHECKMATE:
282     if (winner == p2) {
283      winnerText.text = "CHECKMATE: BLACK wins";
284      AddScore(PLAYER_BLACK);
285     } else if (winner == p1) {
286      winnerText.text = "CHECKMATE: WHITE wins";
287      AddScore(PLAYER_WHITE);
288     }
289    break;
290    case GameOverType.STALEMATE:
291     winnerText.text = "STALEMATE: It's a tie";
292    break;
293    case GameOverType.OUT_OF_TIME:
294     if (winner == p1) {
295      winnerText.text = "OUT OF TIME: WHITE wins";
296      AddScore(PLAYER_WHITE);
297     } else if (winner == p2) {
298      winnerText.text = "OUT OF TIME: BLACK wins";
299      AddScore(PLAYER_BLACK);
300     }
301     break;
302   }
303   continueButton.SetActive(true);
304  }
File name: UIgame.cs Copy
78     IEnumerator WinRoutine()
79     {
80         yield return new WaitForSeconds(1);
81         WinScreen.SetActive(true);
82     }
File name: GameplayController.cs Copy
140  void GameWin(){
141   if(GameController.instance != null && MusicController.instance != null){
142    if(GameController.instance.isMusicOn){
143     AudioSource.PlayClipAtPoint (MusicController.instance.winSound, Camera.main.transform.position);
144    }
145
146    if(GameController.instance.score > GameController.instance.highscore[ GameController.instance.currentLevel - 1]){
147     GameController.instance.highscore [ GameController.instance.currentLevel - 1] = GameController.instance.score;
148    }
149
150    highscore.text = GameController.instance.highscore [GameController.instance.currentLevel].ToString ("N0");
151
152    int level = GameController.instance.currentLevel;
153    level++;
154    if(!(level-1 >= GameController.instance.levels.Length)){
155     GameController.instance.levels [level - 1] = true;
156    }
157
158    GameController.instance.Save ();
159    GameController.instance.currentLevel = level;
160   }
161   gameWinPanel.SetActive (true);
162
163  }
File name: Program.cs Copy
135         private static void MoveBall()
136         {
137             if (ballPositionY == 0)
138             {
139                 ballDirectionUp = false;
140             }
141             if (ballPositionY == Console.WindowHeight - 1)
142             {
143                 ballDirectionUp = true;
144             }
145             if (ballPositionX == Console.WindowWidth - 1)
146             {
147                 SetBallAtTheMiddleOfTheGameField();
148                 ballDirectionRight = false;
149                 ballDirectionUp = true;
150                 firstPlayerResult++;
151                 Console.SetCursorPosition(Console.WindowWidth / 2, Console.WindowHeight / 2);
152                 Console.WriteLine("First player wins!");
153                 Console.ReadKey();
154             }
155             if (ballPositionX == 0)
156             {
157                 SetBallAtTheMiddleOfTheGameField();
158                 ballDirectionRight = true;
159                 ballDirectionUp = true;
160                 secondPlayerResult++;
161                 Console.SetCursorPosition(Console.WindowWidth / 2, Console.WindowHeight / 2);
162                 Console.WriteLine("Second player wins!");
163                 Console.ReadKey();
164             }
165
166             if (ballPositionX < 3)
167             {
168                 if (ballPositionY >= firstPlayerPosition
169                     && ballPositionY < firstPlayerPosition + firstPlayerPadSize)
170                 {
171                     ballDirectionRight = true;
172                 }
173             }
174
175             if (ballPositionX >= Console.WindowWidth - 3 - 1)
176             {
177                 if (ballPositionY >= secondPlayerPosition
178                     && ballPositionY < secondPlayerPosition + secondPlayerPadSize)
179                 {
180                     ballDirectionRight = false;
181                 }
182             }
183
184             if (ballDirectionUp)
185             {
186                 ballPositionY--;
187             }
188             else
189             {
190                 ballPositionY++;
191             }
192
193
194             if (ballDirectionRight)
195             {
196                 ballPositionX++;
197             }
198             else
199             {
200                 ballPositionX--;
201             }
202         }
File name: Program.cs Copy
32     static void Main(string[] args)
33     {
34         SetGameField();
35         StartupScreen();
36
37         isUsed = new bool[Console.WindowWidth, Console.WindowHeight];
38
39
40         while (true)
41         {
42             if (Console.KeyAvailable)
43             {
44                 ConsoleKeyInfo key = Console.ReadKey(true);
45                 ChangePlayerDirection(key);
46             }
47
48
49             MovePlayers();
50
51
52             bool firstPlayerLoses = DoesPlayerLose(firstPlayerRow, firstPlayerColumn);
53             bool secondPlayerLoses = DoesPlayerLose(secondPlayerRow, secondPlayerColumn);
54
55
56             if (firstPlayerLoses && secondPlayerLoses)
57             {
58                 firstPlayerScore++;
59                 secondPlayerScore++;
60                 Console.WriteLine();
61                 Console.WriteLine("Game over");
62                 Console.WriteLine("Draw game!!!");
63                 Console.WriteLine("Current score: {0} - {1}", firstPlayerScore, secondPlayerScore);
64                 ResetGame();
65             }
66             if (firstPlayerLoses)
67             {
68                 secondPlayerScore++;
69                 Console.WriteLine();
70                 Console.WriteLine("Game over");
71                 Console.WriteLine("Second player wins!!!");
72                 Console.WriteLine("Current score: {0} - {1}", firstPlayerScore, secondPlayerScore);
73                 ResetGame();
74             }
75             if (secondPlayerLoses)
76             {
77                 firstPlayerScore++;
78                 Console.WriteLine();
79                 Console.WriteLine("Game over");
80                 Console.WriteLine("First player wins!!!");
81                 Console.WriteLine("Current score: {0} - {1}", firstPlayerScore, secondPlayerScore);
82                 ResetGame();
83             }
84
85
86             isUsed[firstPlayerColumn, firstPlayerRow] = true;
87             isUsed[secondPlayerColumn, secondPlayerRow] = true;
88
89
90             WriteOnPosition(firstPlayerColumn, firstPlayerRow, '*', ConsoleColor.Yellow);
91             WriteOnPosition(secondPlayerColumn, secondPlayerRow, '*', ConsoleColor.Cyan);
92
93
94             Thread.Sleep(100);
95         }
96     }

Download file with original file name:WINS

WINS 127 lượt xem

Gõ tìm kiếm nhanh...