static void Main(string[] args) { Chomp c = new Chomp(); object o = c.moves(100); PrintObj(o); System.Console.In.ReadLine(); }
static void Main(string[] args) { Console.WriteLine("Welcome to the main menu! Enter 1 to play Connect Four, 2 to play Chomp or anything else to exit the program."); bool validInput = false; int input = 0; do { try { input = int.Parse(Console.ReadLine()); } catch (Exception e) { Console.WriteLine("Error: " + e.Message); continue; } validInput = true; } while (!validInput); switch (input) { case 1: //play Connect 4 //ConnectFour.ConnectFour cf = new ConnectFour.ConnectFour(); cf.startGame(); try { ConnectFour.ConnectFour cf = new ConnectFour.ConnectFour(); cf.startGame(); } catch (Exception e) { Console.WriteLine("An error has occurred: " + e.Message); Console.WriteLine(""); } break; case 2: //play chomp Size boardSize = new Size(0, 0); int width = 0; int height = 0; Player.playerType opponentType = Player.playerType.Computer; string[] playerNames = new string[2]; int firstPlayer = -1; validInput = false; do { Console.WriteLine("Please enter the desired width of the board:"); try { width = int.Parse(Console.ReadLine()); } catch (Exception e) { Console.WriteLine("Error: " + e.Message); continue; } validInput = true; } while (!validInput); validInput = false; do { Console.WriteLine("Please enter the desired height of the board:"); try { height = int.Parse(Console.ReadLine()); } catch (Exception e) { Console.WriteLine("Error: " + e.Message); continue; } validInput = true; } while (!validInput); boardSize = new Size(width, height); validInput = false; do { Console.WriteLine("Enter 1 to play against the computer or 2 to play against another person:"); try { int inputNumber = int.Parse(Console.ReadLine()); switch (inputNumber) { case 1: opponentType = Player.playerType.Computer; break; case 2: opponentType = Player.playerType.Human; break; default: throw new Exception("Invalid number."); } } catch (Exception e) { Console.WriteLine("Error: " + e.Message); continue; } validInput = true; } while (!validInput); if (opponentType == Player.playerType.Computer) { Console.WriteLine("Enter your name:"); playerNames[0] = Console.ReadLine(); playerNames[1] = "Computer"; } else { Console.WriteLine("Enter the first player's name:"); playerNames[0] = Console.ReadLine(); Console.WriteLine("Enter the second player's name:"); playerNames[1] = Console.ReadLine(); } validInput = false; do { if (opponentType == Player.playerType.Computer) { Console.WriteLine("Do you want to make the first turn (press 1) or should the computer start (press 2)?"); } else { Console.WriteLine("Which player should start (press 1 or 2 respectively)?"); } try { int inputNumber = int.Parse(Console.ReadLine()); switch (inputNumber) { case 1: case 2: firstPlayer = inputNumber - 1; break; default: throw new Exception("Invalid number."); } } catch (Exception e) { Console.WriteLine("Error: " + e.Message); continue; } validInput = true; } while (!validInput); //Chomp newGame = new Chomp(boardSize, opponentType, playerNames, firstPlayer); try { Chomp newGame = new Chomp(boardSize, opponentType, playerNames, firstPlayer); } catch (Exception e) { Console.WriteLine("Error: " + e.Message); Console.WriteLine(""); } break; default: //exit program return; } }
// Update is called once per frame void Update() { CharacterController contr = pacMan.GetComponent <CharacterController>(); if (superPelletCounter == 4) { superpowered = true; } switch (pacstate) { case PacmanState.Running: speed = (15.0f + ((float)pelletCount / 100)); rolltimer = 1.0f; chargeTimer = 1.0f; if (contr.isGrounded) { direction = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical")); direction = transform.TransformDirection(direction); direction *= speed; if (Input.GetButtonDown("Jump")) { direction.y = jumpSpeed; flightTimer = 1.8f; floatTimer.value = 1.8f; anim.SetBool("JumpB", true); anim.SetFloat("JSpeed", 1); } else { anim.SetBool("JumpB", false); } if (Input.GetButtonDown("Fire2")) { crouch(); } else { anim.SetBool("CrouchButton", false); } } else { direction = new Vector3(Input.GetAxis("Horizontal"), direction.y, Input.GetAxis("Vertical")); direction = transform.TransformDirection(direction); direction.x *= speed; direction.z *= speed; } if (Input.GetAxis("Horizontal") != 0 || Input.GetAxis("Vertical") != 0) { anim.SetFloat("Speed", 1); } else { anim.SetFloat("Speed", 0); } if (direction.y == 0) { anim.SetFloat("JSpeed", 0); } if (Input.GetButton("Fire1")) { if (flightTimer > 0) { fly(); floatTimer.value -= Time.deltaTime; } } else if (Input.GetButton("Submit")) { if (chompTimer > 0) { chompState = Chomp.chomp; anim.SetBool("OnPellet", true); chompTimer -= Time.deltaTime; } else { chompState = Chomp.notChomp; anim.SetBool("OnPellet", false); } } if (chompState == Chomp.notChomp) { chompTimer = 0.5f; } direction.y -= gravity * Time.deltaTime; contr.Move(direction * Time.deltaTime); newRotation = pacMan.transform.eulerAngles; newRotation.y = camera.transform.eulerAngles.y; // lookdirection.eulerAngles = new Vector3(pacMan.transform.rotation.x, camera.transform.rotation.y, pacMan.transform.rotation.z); pacMan.transform.eulerAngles = newRotation; break; case PacmanState.Ducking: direction = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical")); direction = transform.TransformDirection(direction); direction *= speed; direction *= 0.3f; if (Input.GetButtonDown("Fire3")) { pacstate = PacmanState.ChargeUp; } if (Input.GetButtonUp("Fire2") || !contr.isGrounded) { pacstate = PacmanState.Running; } if (Input.GetAxis("Horizontal") != 0 || Input.GetAxis("Vertical") != 0) { anim.SetFloat("Speed", 1); } else { anim.SetFloat("Speed", 0); } direction.y -= gravity * Time.deltaTime; contr.Move(direction * Time.deltaTime); newRotation = pacMan.transform.eulerAngles; newRotation.y = camera.transform.eulerAngles.y; // lookdirection.eulerAngles = new Vector3(pacMan.transform.rotation.x, camera.transform.rotation.y, pacMan.transform.rotation.z); pacMan.transform.eulerAngles = newRotation; break; case PacmanState.Damaged: break; case PacmanState.Rolling: direction = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical")); direction = transform.TransformDirection(direction); direction *= speed; direction *= 5; anim.SetBool("DashButton", true); if (Input.GetAxis("Horizontal") != 0 || Input.GetAxis("Vertical") != 0) { anim.SetFloat("Speed", 1); } else { anim.SetFloat("Speed", 0); } direction.y -= gravity * Time.deltaTime; contr.Move(direction * Time.deltaTime); newRotation = pacMan.transform.eulerAngles; newRotation.y = camera.transform.eulerAngles.y; // lookdirection.eulerAngles = new Vector3(pacMan.transform.rotation.x, camera.transform.rotation.y, pacMan.transform.rotation.z); pacMan.transform.eulerAngles = newRotation; rolltimer -= Time.deltaTime; chargeAndDashSlider.value -= Time.deltaTime; if (rolltimer <= 0) { pacstate = PacmanState.Running; anim.SetBool("DashButton", false); } break; case PacmanState.ChargeUp: if (Input.GetButtonUp("Fire3")) { pacstate = PacmanState.Ducking; break; } chargeTimer -= Time.deltaTime; chargeAndDashSlider.value = 1 - Time.deltaTime; if (chargeTimer <= 0) { pacstate = PacmanState.Rolling; } contr.Move(direction * Time.deltaTime); newRotation = pacMan.transform.eulerAngles; newRotation.y = camera.transform.eulerAngles.y; // lookdirection.eulerAngles = new Vector3(pacMan.transform.rotation.x, camera.transform.rotation.y, pacMan.transform.rotation.z); pacMan.transform.eulerAngles = newRotation; break; case PacmanState.Dead: break; } }